//
//  AppTools.m
//  UI_豆瓣项目
//
//  Created by dllo on 15/10/28.
//  Copyright (c) 2015年 关业达. All rights reserved.
//

#import "AppTools.h"
#import "AFNetworking.h"
@implementation AppTools

+ (void)geturlStr:(NSString *)urlStr Block:(AppToolBlock)block
{
    
    // 编码
    NSString *urlEncode = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    //[NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];  代表支持所有的接口类型
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    [manager GET: urlEncode parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
      
        
        // block回调
        block(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"失败==== %@",error);
        
    }];

}


+ (void)getImageWithURL:(NSString *)url Block:(AppToolImageBlock)block
{
    NSURL *url1 = [NSURL URLWithString:url];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url1];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        block(data);
        
    }];
    [task resume];
    
    
}
















@end
